/*
 * Classname Cookie.java
 * 
 * Version Information
 * Date Mar 21, 2006
 *
 * Copyright (c) AmSoft Systems, 2006
 */
package net.amsoft.iservice.isso.hibernate;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import net.amsoft.iservice.util.exception.IServiceException;
import org.apache.log4j.Logger;

/**
 * @author jyoti
 * 
 */
public class Cookie extends ISSOObject {
    private static Logger logger = Logger.getLogger(Cookie.class);
    private String encCookieName;
    private int typeFlag;
    private Principal principal;
    private Set<Response> response = new HashSet<Response>();

    public Cookie() {
    }

    public String getEncCookieName() {
        return this.encCookieName;
    }

    public void setEncCookieName(String encCookieName) {
        this.encCookieName = encCookieName;
    }

    public int getTypeFlag() {
        return this.typeFlag;
    }

    public void setTypeFlag(int typeFlag) {
        this.typeFlag = typeFlag;
    }

    public Principal getPrincipal() {
        return this.principal;
    }

    public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

    public Set getResponse() {
        return this.response;
    }

    public void setResponse(Set<Response> response) {
        this.response = response;
    }

    public void debug(String prefix) {
        logger.debug(prefix + " : Cookie  (" + id + ", " + encCookieName + ", "
                + typeFlag + " , " + creationTime + " , " + modificationTime
                + "  , " + principal.getId() + ")");
    }

    public void addResponse(Response response) throws IServiceException {
        response.setCookie(this);
        this.response.add(response);
        response.insert();
    }

    public void removeResponse(Response oResponse) {
        this.response.remove(oResponse);
        oResponse.remove();
    }

    /**
     * function used to update the cookie object
     * 
     * @param modTime
     *            if true then modification time will also be updated by current
     *            time
     * @return
     */
    public Cookie update(boolean modTime) {
        if (modTime) {
            this.setModificationTime(new Date());
            return (this);
        } else {
            return (Cookie) update();
        }
    }

    public Cookie update() {
        return (this);
    }
}